package vn.pdg.zoombie.ui;

import java.io.File;

import vn.pdg.zoombie.bean.Utils;
import vn.pdg.zoombie.ui.zoomimager.ImageViewTouch;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class AdjustPhoto extends BaseActivity implements OnClickListener {

	public static final String EXTRA_URL_PHOTO = "EXTRA_URL_PHOTO";
	public static final String EXTRA_ORIENT_PHOTO = "EXTRA_ORIENT_PHOTO";
	private ImageViewTouch imageAdjust;
	private ImageView backBtn;
	private Button btCancle, btOk;
	private String urlPhoto;
	private String orientPhoto;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.adjust_photo);
		
		loadControl();
		loadData();

	}

	public void loadControl() {

		titleLayout = (LinearLayout) findViewById(R.id.title_layout);
		titleLayout.setBackgroundResource(R.drawable.title_zombifier);
		layoutMenu = (LinearLayout) findViewById(R.id.layoutmenu);
		layoutMenu.setBackgroundResource(R.drawable.adjust_pinch_swipe);
		backBtn = (ImageView) findViewById(R.id.btnback);
		backBtn.setBackgroundResource(R.drawable.adjust_cancel);

		btCancle = (Button) findViewById(R.id.bt_cancle);
		btOk = (Button) findViewById(R.id.bt_ok);
		imageAdjust = (ImageViewTouch) findViewById(R.id.image_adjust);
		btCancle.setOnClickListener(this);
		btOk.setOnClickListener(this);
	}

	private void loadData() {
		Intent data = getIntent();
		urlPhoto = data.getStringExtra(EXTRA_URL_PHOTO);
		orientPhoto = data.getStringExtra(EXTRA_ORIENT_PHOTO);
		int degrees = 0;
		if (orientPhoto != null)
			degrees = Integer.parseInt(orientPhoto);

		Bitmap b = Utils.decodeFile(new File(urlPhoto), 320);
		b = Utils.rotate(b, degrees);

		imageAdjust.setImageBitmapReset(b, 0, true);

	}

	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.bt_ok:

			break;
		case R.id.bt_cancle:
			finish();
			break;
		default:
			break;
		}
	}
}
